﻿<?php
if(!empty($_POST)){
if(!isset($_POST["email"]) || empty($_POST["email"])){
	$email_error = "邮箱不能为空";
}else{
	$email = $_POST["email"];
}
if(!isset($_POST["password"]) || empty($_POST["password"])){
	$password_error = "密码不能为空";
}else{
	$password = $_POST["password"];
}
if(isset($email_error) || isset($password_error)){
	$error_msg = "<ul class='errors'>";
	if(isset($email_error)){
		$error_msg .= "<li>$email_error</li>";
	}
	if(isset($password_error)){
		$error_msg .= "<li>$password_error</li>";
	}
	$error_msg .= "</ul>";
}else{
	require_once("classes/mustang.php");
	require_once("classes/developer.php");
	$mustangDB = new MustangDB();
	$dev = new Developer($mustangDB);
	if($dev->initWithEmailPassword($email, $password)){
		session_start();
		$_SESSION['developer'] = $dev->getInfo();
		header("Location: /php/developer.php");
	}else{
		$error_msg = "<ul class='errors'><li>用户名/密码错误</li></ul>";
	}
}
}
?>

<html>
<head>
<title>开发者登录</title>
<style type="text/css">
ul.form{
	list-style-type: none;
	width: 800px;
}
ul.errors{
	list-style-type: circle;
	list-style-position: inside;
	color: red;
	text-align: left;
}
</style>
</head>
<body>
<?php 
	if(isset($error_msg)){
		echo $error_msg;
	}elseif(isset($success_msg)){
		echo $success_msg;
		exit;
	}
?>
<div>开发者注册</div>
<form action="#" method="post">
<ul class="form">
<li><label>邮箱</label><input name="email" type="text" value="<?php if(isset($email)){echo $email;} ?>"/></li>
<li><label>密码</label><input name="password" type="password" /></li>
<li><label></label><input name="submit" type="submit" value="登录"/></li>
<ul>
</form>
</body>
</html>